﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace ActionSystem.Core.Utils
{
    /// <summary>
    /// mono类型，可以实现在场景中添加
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class MonoSingleton<T> : MonoBehaviour where T:MonoSingleton<T>
    {
        private static T _instance = null;
        public static T Instance
        {
            get
            {
                if (_instance == null)
                {
                    GameObject obj = new GameObject(typeof(T).Name);
                    _instance = obj.AddComponent<T>();
                    DontDestroyOnLoad(_instance);
                }
                return _instance;
            }
        }
        private void Awake()
        {
            Init();
        }
        public virtual void Init() { }
    }
}


